#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "common.h"
#include <string.h>
#include <stdlib.h>
#define DEV IMG_DEV
// cameraID=0,x=22,y=34,enable=1,imgPath=图片路径
char wmark_str[256] = {"cameraID=0,x=22,y=34,enable=1,str=/data/vendor/wmark/log.png"};
int flag = 0;
int main(int argc, char**argv)
{
    int fd;
    char num[3];
    int enable = 1;
    int cameraId = 2; // faceId=2 代表第 0 个摄像头

    if (argc  < 2) {
        printf("help:\n\t%s cameraId\n", argv[0]);
        printf("说明:\n\t %s 2 : 给第一个摄像头 加水印\n", argv[0]);
    }
    if (argc >= 2) {
        cameraId = atoi(argv[1]);
        if (cameraId < 2) {
            printf("请输入 cameraId >= 2");
            cameraId = 2;
        }
    }

    printf("cameraId = %d\n", cameraId);

    fd = open(DEV, O_RDWR);
    if (fd == - 1) {
        printf("device open failure\n");
        return -1;
    }
    int x = 0;
    int y = 0;
    while(1) {
        memset((void *)wmark_str, 0, sizeof(wmark_str));
        if (1) {
            sprintf(wmark_str, "cameraID=%d,x=%d,y=%d,enable=%d,str=/data/vendor/wmark/%s", cameraId, 5 * x, x, enable,"log-1.png");
            flag = 0;
        }else {
            sprintf(wmark_str, "cameraID=%d,x=%d,y=%d,enable=1,str=/data/vendor/wmark/%s", cameraId, 5 * x, x, "log.png");
            flag = 1;
        }
        
        write(fd, wmark_str, sizeof(wmark_str));
        x++;
        if (x > 900) {
            x = 0;
        }

        usleep(20000);
    }
    close(fd);
    return 0;
}
